package com.javasm.mingming.login.jwt;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author javasm
 * @version 0.1
 * @className JwtToken
 * @descriptioin:
 * @date 2025/1/13 15:57
 * @since jdk11
 */
public class JwtToken extends AbstractAuthenticationToken {

    private String token;

    private UserDetails userDetails;

    public JwtToken(String tokenStr) {
        super(null);
        this.token = tokenStr;
        this.setAuthenticated(false);
    }

    public JwtToken(UserDetails userDetails) {
        super(userDetails.getAuthorities());
        this.userDetails = userDetails;
        this.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.userDetails;
    }

    public String getToken(){
        return this.token;
    }
}
